/********************************
 *版权所有 CopyRight(c) 快程乐码信息有限公司所有，未经授权，不得复制、转发
 */
package com.jyx.excel.util;

import java.io.File;
import java.io.InputStream;

/************
 *@Author yejx
 *@version v1.0
 *@create 2020/7/11 13:42
 *@Description TODO
 *
 */
    public class TestFileUtil {


        public static InputStream getResourcesFileInputStream(String fileName) {
            return Thread.currentThread().getContextClassLoader().getResourceAsStream("" + fileName);
        }

        public static String getPath() {
           //class.getResource("/") == class.getClassLoader().getResource("")
            return TestFileUtil.class.getResource("/").getPath();
        }

        public static File createNewFile(String pathName) {
            File file = new File(getPath() + pathName);
            if (file.exists()) {
                file.delete();
            } else {
                if (!file.getParentFile().exists()) {
                    file.getParentFile().mkdirs();
                }
            }
            return file;
        }

        public static File readFile(String pathName) {
            return new File(getPath() + pathName);
        }

        public static File readUserHomeFile(String pathName) {
            return new File(System.getProperty("user.home") + File.separator + pathName);
        }
    }
